import request from '@/utils/request'

// 用户登录
export function login({ username, password }) {
  const data = {
    loginName: username,
    password: password
  }
  return request({
    url: '/login',
    method: 'post',
    params: data
  })
}

// 获取用户信息
export function getInfo(token) {
  return request({
    url: '/users/1',
    method: 'get'
  })
}

// 退出登录
export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

// 获取用户列表
export function getUserList(query) {
  return request({
    url: '/users',
    method: 'GET',
    params: query
  })
}

// 创建用户
export function creatUser(userData) {
  return request({
    url: '/users',
    method: 'POST',
    data: userData
  })
}

// 更新用户
export function updateUser(userData) {
  return request({
    url: '/users',
    method: 'PUT',
    data: userData
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: '/users/' + id,
    method: 'DELETE'
  })
}

// 获取角色列表
export function getRoleList(query) {
  return request({
    url: '/roles',
    method: 'GET',
    params: query
  })
}

// 创建角色
export function creatRole(roleData) {
  return request({
    url: '/roles',
    method: 'POST',
    data: roleData
  })
}

// 更新角色
export function updateRole(roleData) {
  return request({
    url: '/roles',
    method: 'PUT',
    data: roleData
  })
}

// 删除角色
export function deleteRole(id) {
  return request({
    url: '/roles/' + id,
    method: 'DELETE'
  })
}

export function getMenuTree() {
  return request({
    url: '/resources',
    method: 'GET'
  })
}
